######################################################################
# Time-stamp: <05/08/11 18:28:21 ostolop>
#
# Package: EP::Core::Data::Parser::Factory
#
# The Parser Factory class
######################################################################
package EP::Core::Data::Parser::Factory;

use strict;

use EP::Common;
use EP::Common::Error qw ( :try );

# sub: create_data_parser
#   Instantiates a new data parser.
# parameters:
#   data_type  - The type of data to be parsed. *One* of: user_exp, affy, genepix, fasta, ...
#   query      - The CGI query object.
#   caller_epc - Reference to the calling EPC instance.
#
# returns:
#    A new instance of an appropriate subclass of <EP::Core::Data::Parser>.
sub create_data_parser {
  my $class = shift;
  my %params = @_;

  my $parser = "EP::Core::Data::Parser::" . $params{data_type};

  try {
    warn ("Loading data parser $parser");
    $parser->require;
  } otherwise {
    warn "Failed to load data parser $parser: $UNIVERSAL::require::ERROR";
    throw EP::Common::Error ( -value => CUD_PARSER_LOAD_FAILURE );
  };

  return $parser->new ( %params );
}

1;
